package com.example.demo.mapper;

import com.example.demo.entity.Like;
import org.apache.ibatis.annotations.*;

@Mapper
public interface LikeMapper {
    int insertLike(Like like);
    Like selectLikeById(Long id);
    Like selectLikeByUserAndPost(@Param("userId") Long userId, @Param("postId") Long postId);

    @Select("SELECT * FROM likes WHERE user_id = #{userId} AND comment_id = #{commentId}")
    Like selectLikeByUserAndComment(@Param("userId") Long userId, @Param("commentId") Long commentId);

    @Delete("DELETE FROM likes WHERE id = #{id}")
    int deleteLikeById(Long id);

    @Delete("DELETE FROM likes WHERE user_id = #{userId} AND post_id = #{postId}")
    int deleteLikeByUserAndPost(@Param("userId") Long userId, @Param("postId") Long postId);

    @Delete("DELETE FROM likes WHERE user_id = #{userId} AND comment_id = #{commentId}")
    int deleteLikeByUserAndComment(@Param("userId") Long userId, @Param("commentId") Long commentId);

    @Select("SELECT COUNT(*) FROM likes WHERE post_id = #{postId}")
    int countLikesByPostId(Long postId);

    @Select("SELECT COUNT(*) FROM likes WHERE comment_id = #{commentId}")
    int countLikesByCommentId(Long commentId);
}